import 'nprogress/nprogress.css'
import NotFound from '@/views/NotFound.vue'
import { start, done, configure } from 'nprogress'
import path from 'path'

configure({
  trickleSpeed: 20,
  showSpinner: false
})

function delay(duration: number) {
  return new Promise<void>((resolve) => {
    setTimeout(() => {
      resolve()
    }, duration)
  })
}

function getPageComponent(pageCompResolver: Function) {
  return async () => {
    start()
    if (process.env.NODE_ENV === 'development') {
      await delay(300)
    }
    const comp = await pageCompResolver()
    done()
    return comp
  }
}
export default [
  {
    path: '/',
    redirect: '/O'
  },
  {
    name: 'Home',
    path: '/O',
    component: getPageComponent(() => import('@/views/Home/index.vue')),
    meta: {
      title: '首页'
    }
  },
  {
    name: 'About',
    path: '/Oabout',
    component: getPageComponent(() => import('@/views/About/index.vue')),
    meta: {
      title: '关于我'
    }
  },
  {
    name: 'Blog',
    path: '/Oarticle',
    component: getPageComponent(() => import('@/views/Blog/index.vue')),
    meta: {
      title: '文章'
    },
    children: [
      {
        name: 'CategoryBlog',
        path: '/Oarticle/cate/:categoryId',
        component: getPageComponent(() => import('@/views/Blog/index.vue')),
        meta: {
          title: '文章'
        }
      }
    ]
  },
  {
    name: 'BlogDetail',
    path: '/Oarticle/:id',
    component: getPageComponent(() => import('@/views/Blog//Detail.vue')),
    meta: {
      title: '文章详情'
    }
  },
  {
    name: 'Project',
    path: '/Oproject',
    component: getPageComponent(() => import('@/views/Project/index.vue')),
    meta: {
      title: '项目&效果'
    }
  },
  {
    name: 'Message',
    path: '/Omessage',
    component: getPageComponent(() => import('@/views/Message/index.vue')),
    meta: {
      title: '留言板'
    }
  },
  { name: 'NotFound', path: '/:pathMatch(.*)', component: NotFound }
]
